package com.jd.platform.gobrs.client.handler;

import com.jd.platform.gobrs.client.gcache.LocalCache;
import com.jd.platform.gobrs.client.gcache.LocalCacheFactory;
import com.jd.platform.gobrs.common.model.typeenum.KeyType;

/**
 * @program: gobrs
 * @ClassName AbstoryAutoCacheFactory
 * @description: 自动上报
 * @author: sizegang
 * @create: 2022-01-08 15:12
 * @Version 1.0
 **/
public abstract class AbstractAutoCacheHandler extends CommonCacheHandler {

    private LocalCacheFactory localCacheFactory = new LocalCacheFactory();
    @Override
    public Object getCache(String key) {
        return doGetCache(key, null);
    }

    @Override
    public boolean setCache(String key, Object value) {
        return doSetCache(key, value);
    }

    public abstract Object doGetCache(String key, KeyType keyType);

    public LocalCache getNonNullCache(String key) {
        return localCacheFactory.getNonNullCache(key);
    }

    /**
     * 判断这个key是否在被探测的规则范围内
     */
    public boolean inRule(String key) {
        return localCacheFactory.getNonNullCache(key) != null;
    }
}
